<template>
  <div>
    <headerbar>
      培训计划
      <!--<span @click="go('trainingPlanAdd')" class="head-btn" slot="btn">+ 添加</span>-->
    </headerbar>
    <section class="">

      <div class="d-scroll list-wenda" style="">
        <cube-scroll
          ref="scroll"
          :options="options"
          @pulling-up="onPullingUp"
        >
          <div v-for="(item,index) in list" @click="goDetail(item)" class="item block">
            <div class="icon">
              <span class="icon-text">计</span>
            </div>
            <div class="text-wrap">
              <div class="title"><span class="pdr-2">{{item.trainingclass}}</span>
                <span class="status" :class="rendClass(item.type)">{{status[item.type]}}</span>
              </div>
              <!--<div class="tip">
                <span>辅导师：黄小明</span><span>{{tools.formateYearSecond(item.createTime)}}</span><span>人数：{{item.number}}</span>
              </div>-->
              <div class="tip">
                <span class="one">办班单位：{{item.deptname}}</span>
              </div>
              <div class="tip">
                <span class="one">培训时间：{{item.time}}</span><span>培训天数：{{item.days || '未定'}}</span>
              </div>
            </div>
          </div>



        </cube-scroll>
      </div>
    </section>
  </div>
</template>


<script>
  export default {
    name: 'trainingPlan',
    data () {
      return {
        status: {
          0: '计划填报',
          1: '计划审核中',
          2: '计划审核通过',
          3: '计划审核不通过',
          4: '计划取消审核中',
          5: '计划取消审核通过',
          6: '计划取消审核不通过',
          7: '培训完成'
        },
        options: {
          pullUpLoad: true,
          scrollbar: false
        },
        pageIndex: 1,
        pageSize: 10,
        list: []
      }
    },
    created () {
      this.loadData()
    },
    methods: {
      rendClass (type) {
        // 业务状态 0 计划填报 1计划审核中 2计划审核通过 3计划审核不通过 4计划取消审核中 5 计划取消审核通过 6计划取消审核不通过 7培训完成
        type = parseInt(type)
        if ('0,1,3,4,5,6'.split(',').indexOf(type) >= 0) {
          return 'color-red'
        }
        if (2 === type) {
          return 'color-green'
        }
        if (7 === type) {
          return 'color-tip'
        }
      },
      go (name) {
        this.$router.push({name: name})
      },
      goDetail (data) {
        this.$store.state.trainingPlanDetail = data
//        if (data.type == 7) {
//          return this.$router.push({name: 'trainingplanStartedDetail', query: {id: data.id, numberofperiods: data.numberofperiods}})
//        }
        this.$router.push({name: 'trainingPlanDetail', query: {id: data.id, numberofperiods: data.numberofperiods}})
      },
      loadData () {
        let params = {
          "limit": this.pageSize,
          "page": this.pageIndex,
          "state": "0"
        }
        return this.fetchService.trainingPlanInfoList(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          if (res.data.length === 0) {
            this.tools.tip('已无更多数据')
          }
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate()
          this.list = this.list.concat(res.data)
          return res
        })
      },
      onPullingUp () {
        this.pageIndex++
        this.loadData().then(res => {
          setTimeout(() => {
            this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
            this.options.isPullUpLoad = !true
          }, 100)
        })
      }
    }
  }
</script>

<style scoped>

</style>
